package com.wzr.comparetool;

import java.util.ArrayList;

/**
 * Ignored table or view in a new db scan
 * 文件中可以包含单行注释
 * 以"tb."开头的为表
 * 以"vw."开头的为视图
 * 不加前缀的表和视图都有
 */
public class TableViewIgnore {

	public static final String VIEW_PREFIX = "vw.";
	public static final String TABLE_PREFIX = "tb.";
	public static final String COMMENT_PREFIX = "//";
	private String ignoreFilePath;
	private ArrayList<String> tableIgnoreList;
	private ArrayList<String> viewIgnoreList;

	public ArrayList<String> getTableIgnoreList() {
		return tableIgnoreList;
	}

	public ArrayList<String> getViewIgnoreList() {
		return viewIgnoreList;
	}

	public TableViewIgnore(String ignoreFilePath) {
		this.ignoreFilePath = ignoreFilePath;
		ArrayList<String> lineList = FileUtil.readTxtLines(ignoreFilePath);
		try {

			for (String aLine : lineList) {
				if (aLine.isEmpty() || aLine.startsWith(COMMENT_PREFIX)) {
					// This line is empty or a comment
					continue;
				}
				if (aLine.startsWith(VIEW_PREFIX)) {
					// This line is view
					if (this.viewIgnoreList == null) {
						this.viewIgnoreList = new ArrayList<>();
					}
					this.viewIgnoreList.add(aLine.substring(VIEW_PREFIX.length()));
					continue;
				}
				if (aLine.startsWith(TABLE_PREFIX)) {
					// This line is table
					if (this.tableIgnoreList == null) {
						this.tableIgnoreList = new ArrayList<>();
					}
					this.tableIgnoreList.add(aLine.substring(TABLE_PREFIX.length()));
					continue;
				}
				// This line is view or table
				if (this.viewIgnoreList == null) {
					this.viewIgnoreList = new ArrayList<>();
				}
				this.viewIgnoreList.add(aLine);
				if (this.tableIgnoreList == null) {
					this.tableIgnoreList = new ArrayList<>();
				}
				this.tableIgnoreList.add(aLine);
			}

		} catch (Exception exp) {
			exp.printStackTrace();
		}
	}
}
